/**
 * Copyright 2009 by Christian Scheid. This file is part of the switch eclipse plugin and is licensed under the
 * GPL version 3. Please refer to the URL http://www.gnu.org/licenses/gpl-3.0.html for details.
 */
package org.digitalsoul.switchplugin.prefs.wizards;

import org.digitalsoul.switchplugin.prefs.ItemsUI;
import org.digitalsoul.switchplugin.prefs.util.ItemListConfigurator;

public class NewItemWizard extends NewThingWizard {

    private ItemListConfigurator configurator;
    private ItemsUI itemsUI;

    public NewItemWizard(ItemsUI itemsUI, ItemListConfigurator configurator) {
        this.itemsUI = itemsUI;
        this.configurator = configurator;
    }

    @Override
    protected String getLabelText() {
        return "Item Name: ";
    }

    @Override
    protected String getPageDescription() {
        return "Create a new Switch Item";
    }

    @Override
    protected String getPageId() {
        return "new.switch.item.wizard";
    }

    @Override
    protected String getTitle() {
        return "Create Switch Item";
    }

    @Override
    protected boolean validateName(String text) {
        boolean setAlreadyExists = configurator.hasItem(text.trim());
        if (setAlreadyExists) {
            setErrorMessage("A Switch Item with this name already exists");
        }
        else setErrorMessage(null);
        return !setAlreadyExists;
    }

    @Override
    public boolean performFinish() {
        itemsUI.addItem(textField.getText().trim());
        return true;
    }
}
